package com.qf.controller;


import com.qf.service.GoodsService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @GetMapping("/selectAll")//查询所有商品
    public ResultMsg selectAll(){
        return goodsService.selectAll();
    }

    @GetMapping("/selectOne")//根据id查商品详细信息
    public ResultMsg selectOne(Integer gid){
        return goodsService.selectOne(gid);
    }

    @GetMapping("/selectBySortIdAndOne")//查询所有一级目录——二级目录下对应的所有商品
    public ResultMsg selectBySortIdAndOne(Integer sid){
        return goodsService.selectBySortIdAndOne(sid);
    }

    @GetMapping("/selectByGoodsIdAndOne")//根据商品ID查询该目录下对应的所有商品
    public ResultMsg selectByGoodsIdAndOne(Integer gid){
        return goodsService.selectByGoodsIdAndOne(gid);
    }

    @GetMapping("/selectLike")//模糊查询
    public ResultMsg selectLike(String src){
        return goodsService.selectLike(src);
    }

    //查询10个商品
    @GetMapping("/findAll")
    public ResultMsg findAll(@RequestParam(required = false,defaultValue = "1")int start,@RequestParam(required = false,defaultValue = "10")int end){
        return goodsService.findAll(start,end);
    }
}
